﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Elderos.Utils
{
    public class GaussianRandom
    {
        private double _mean;
        private double _standartDeviation;

        private Random _rand = new Random();

        public GaussianRandom(double mean, double standartDeviation)
        {
            _mean = mean;
            _standartDeviation = standartDeviation;
        }

        public double Next()
        {
            double u1 = _rand.NextDouble();
            double u2 = _rand.NextDouble();
            double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) *
                         Math.Sin(2.0 * Math.PI * u2); //random normal(0,1)
            double randNormal =
                         _mean + _standartDeviation * randStdNormal;

            return randNormal;
        }
    }
}
